<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('接口管理列表')" />
    <th:block th:include="include :: datetimepicker-css" />
    <style>
        .select-list li label:not(.radio-box){
            width: 80px;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>日期：</label>
                            <input type="text" name="lastMonth" id="lastMonth" placeholder="yyyy-MM-dd" onchange="dateChange()" autocomplete="off" th:value="${lastMonth}">
                        </li>
                        <li>
                            <label>检测时间：</label>
                            <input type="text" id="dtSysModi" autocomplete="off" disabled style="border: 0px" >
                        </li>
                        <li>
                            <label>得分：</label>
                            <input type="text" id="score" autocomplete="off" disabled style="border: 0px" >
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="allDataCheck()"><i class="fa fa-edit"></i>&nbsp;数据核对</a>
                            <a class="btn btn-info btn-rounded btn-sm" onclick="scoreCalculate()"><i class="fa fa-refresh"></i>&nbsp;重新计分</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="tabs-container" style="margin-top: 80px">
            <ul class="nav nav-tabs"  id="tabs">
                <li class="active"><a data-toggle="tab" type="ods" href="#tab-1" aria-expanded="true">贴源层（<span id="scoreOds" ></span>分）</a>
                </li>
                <li class=""><a data-toggle="tab" type="dw" href="#tab-2" aria-expanded="false">数仓层（<span id="scoreDw" ></span>分）</a>
                </li>
                <li class=""><a data-toggle="tab" type="dm" href="#tab-3" aria-expanded="false">统计层（<span id="scoreDm" ></span>分）</a>
                </li>
            </ul>
            <div class="tab-content">
                <div id="tab-1" class="tab-pane active">
                    <div class="panel-body">
                        <div class="col-sm-12 select-table table-striped">
                            <table id="ods-table"></table>
                        </div>
                    </div>
                </div>
                <div id="tab-2" class="tab-pane">
                    <div class="panel-body">
                        <div class="col-sm-12 select-table table-striped">
                            <table id="dw-table"></table>
                        </div>
                    </div>
                </div>
                <div id="tab-3" class="tab-pane">
                    <div class="panel-body">
                        <div class="col-sm-12 select-table table-striped">
                            <table id="dm-table"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "base/etl/check/item";
    var dbData = [[${@baseDbService.selectAll()}]];
    var dataCheck = function (param) {
        $.ajax({
            url: ctx+'base/etl/check/dataCheck',
            type: 'post',
            dataType: 'json',
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify(param),
            success: function (result) {
                if(result.code==0) {
                    var type = $(".nav-tabs li.active a").attr("type");
                    tableDataRefresh(type);
                    scoreCalculate();
                    $.modal.alertSuccess("已重新核对")
                } else {
                    $.modal.alertError("核对失败："+result.msg);
                }
            }
        });
        $.modal.alertWarning("数据核对中，您可以持续刷新表格查看进度");
    }

    var tableDataRefresh = function(execType) {
        $('#'+execType+"-table").bootstrapTable("destroy");
        $('#'+execType+"-table").bootstrapTable({
            url: prefix + "/list?euCls="+execType+"&mm="+$("#lastMonth").val()+"&dateType=m",
            method: 'post',
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "接口管理",
            showRefresh: true,
            showSearch: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'idDataCheckItem',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'cd',
                    title: '编码'
                },
                {
                    field: 'na',
                    title: '名称'
                },
                {
                    field: 'valSour',
                    title: '源值'
                },
                {
                    field: 'valTar',
                    title: '目标值'
                },
                {
                    field: 'valDiff',
                    title: '差值'
                },
                {
                    field: 'timesSour',
                    title: '耗时(毫秒)'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-primary btn-xs " href="javascript:void(0)" onclick="onTableDataCheck(\'' + row.na + '\',\''+row.cd+'\',\''+row.euCls+'\')"><i class="fa fa-edit"></i>修正</a> ');
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="toDayDetail(\''+row.cd+'\')"><i class="fa fa-list"></i>明细</a> ');
                        return actions.join('');
                    }
                }]
        });
    };
    var toDayDetail = function (tableName) {
        $.modal.open("天明细",ctx+"base/etl/check/toDayDetail?month="+$("#lastMonth").val()+"&tableName="+tableName);
    }
    var dateChange = function () {
        var lastMonth = $("#lastMonth").val();
        $.ajax({
            url: ctx+'base/etl/check/getByDate?dateType=m&mm='+$("#lastMonth").val(),
            type: 'get',
            success: function (result) {
                if(result.code==0) {
                    debugger;
                    var data = result.data;
                    $("#score").val(data.score);
                    $("#dtSysModi").val(data.dtSysModi);
                    $("#scoreOds").text(data.scoreOds);
                    $("#scoreDw").text(data.scoreDw);
                    $("#scoreDm").text(data.scoreDm);
                    var type = $("#tabs").find("li.active a").attr("type");
                    tableDataRefresh(type);
                } else {
                    $.modal.alertError("核对失败："+result.msg);
                }
            }
        });
    }
    var allDataCheck = function () {
        $.modal.confirm("确定要核对["+$("#lastMonth").val()+"]的数据吗？", function() {
            dataCheck({"monthOrDay":$("#lastMonth").val(),"type":"all","dateType":"m"});
        });
    };
    var onTableDataCheck = function (des,tableName,type) {
        $.modal.confirm("确定要重新核对["+des+"]的数据吗？", function() {
            dataCheck({"monthOrDay":$("#lastMonth").val(),"type":type,"tableName":tableName,"dateType":"m"});
        });
    };
    var scoreCalculate = function () {
        $.modal.confirm("确定重新计算["+$("#lastMonth").val()+"]的分数吗？", function() {
            $.ajax({
                url: ctx+'base/etl/check/scoreCalculate?type=m&mm='+$("#lastMonth").val(),
                type: 'get',
                success: function (result) {
                    if(result.code==0) {
                        debugger;
                        var data = result.data;
                        $("#score").val(data.score);
                        $("#dtSysModi").val(data.dtSysModi);
                        $("#scoreOds").text(data.scoreOds);
                        $("#scoreDw").text(data.scoreDw);
                        $("#scoreDm").text(data.scoreDm);
                        $.modal.alertSuccess("计算完成");
                    } else {
                        $.modal.alertError("计算失败："+result.msg);
                    }
                }
            });
        });
    };
    function dataDiffCheck(tableName) {
        $.modal.openTab("差异化核对",ctx+"base/etl/check/toDayDetail?tableName="+tableName+"&month="+$("#lastMonth").val());
    };
    $(function() {
        $("#lastMonth").datetimepicker({
            format: "yyyy-mm",
            startView: 3,
            minView: 3,
            autoclose: true
        });
        tableDataRefresh("ods");
        $('#tabs a').click(function (e) {
            var type = $(this).attr("type");
            tableDataRefresh(type);
        });
        dateChange();
    });
    function preview(outerId) {
        var url = prefix + '/preview/' + outerId;
        $.modal.openTab("接口数据预览", url);
    }
</script>
</body>
</html>